<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of User
 *
 * @author neozilon
 */
class Admin_Form_User extends Zend_Form{

    public function addUser(){
        $this->setName('add_user_form');
        $this->setAction('/admin/users/add')
              ->setMethod('post');
        $this->setAttrib('id', 'add_user_form');
        $this->setIsArray(true);
        $this->setElementsBelongTo('user');

        $username = new Zend_Form_Element_Text('username');
        $username->setLabel('Usuario:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input')
                ->setValue('')
                ->addValidator('alnum');

        $passwd = new Zend_Form_Element_Password('passwd');
        $passwd->setLabel('Contraseña:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input');
        
        $passwd2 = new Zend_Form_Element_Password('passwd2');
        $passwd2->setLabel('Ingresar Contraseña de nuevo:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input');

        $fullname = new Zend_Form_Element_Text('fullname');
        $fullname->setLabel('Nombre Completo:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input');

        $email = new Zend_Form_Element_Text('email');
        $email->setLabel('Correo electrónico: ')
                ->setRequired(true)
                ->setAttrib('class', 'text-input')
                ->addValidator('emailAddress');

        $website = new Zend_Form_Element_Text('website');
        $website->setLabel('Pagina web:')
                ->addValidator(new Nosql_Validate_Uri())
                ->setAttrib('class', 'text-input');

        $roles = array(Nosql_Acl_ModuleAcl::ROLE_ADMIN  =>'Administrador',
                       Nosql_Acl_ModuleAcl::ROLE_AUTHOR =>'Autor/Editor',
                       Nosql_Acl_ModuleAcl::ROLE_USER => 'Usuario');
        $role = new Zend_Form_Element_Select('role');
        $role->setLabel('Tipo de usuario')
            ->setMultiOptions($roles);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Agregar Usuario')
                ->setAttrib('class', 'button')
                ->setAttrib('escape', false);

        $this->addElements(array($username, $passwd, $passwd2, $fullname, $email, $website, $role,$submit));

        $this->setElementDecorators(array(
                'viewHelper',
                'label',
                'errors',
                array('htmlTag',array('tag' =>'p'))

        ));

        $this->addDecorator('formElements');
        $this->submit->removeDecorator('Label');
        $this->addDecorator('form');

        return $this;
    }

    public function editUser($userId){
        $this->setName('edit_user_form');
        $this->setAction('/admin/users/edit/user/' . $userId)
              ->setMethod('post');
        $this->setAttrib('id', 'edit_user_form');
        $this->setIsArray(true);
        $this->setElementsBelongTo('user');

        $username = new Nosql_Form_Element_Label('username');
        $username->setLabel('Usuario:')
                ->setAttrib('class', 'labelval');
        
        $passwd = new Zend_Form_Element_Password('passwd');
        $passwd->setLabel('Ingresar nueva contraseña:')
                ->setAttrib('class', 'text-input');

        $passwd2 = new Zend_Form_Element_Password('passwd2');
        $passwd2->setLabel('Reingresar contraseña nueva:')
                ->setAttrib('class', 'text-input');

        $fullname = new Zend_Form_Element_Text('fullname');
        $fullname->setLabel('Nombre Completo:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input');

        $email = new Zend_Form_Element_Text('email');
        $email->setLabel('Correo electrónico: ')
                ->setRequired(true)
                ->setAttrib('class', 'text-input')
                ->addValidator('emailAddress');

        $website = new Zend_Form_Element_Text('website');
        $website->setLabel('Pagina web:')
                ->addValidator(new Nosql_Validate_Uri())
                ->setAttrib('class', 'text-input');

        $roles = array(Nosql_Acl_ModuleAcl::ROLE_ADMIN  =>'Administrador',
                       Nosql_Acl_ModuleAcl::ROLE_AUTHOR =>'Autor/Editor',
                       Nosql_Acl_ModuleAcl::ROLE_USER => 'Usuario');
        $role = new Zend_Form_Element_Select('role');
        $role->setLabel('Tipo de usuario')
            ->setMultiOptions($roles);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Actualizar Usuario')
                ->setAttrib('class', 'button')
                ->setAttrib('escape', false);

        $this->addElements(array($username, $passwd, $passwd2, $fullname, $email, $website, $role,$submit));

        $this->setElementDecorators(array(
                'viewHelper',
                'label',
                'errors',
                array('htmlTag',array('tag' =>'p'))

        ));

        $this->addDecorator('formElements');
        $this->submit->removeDecorator('Label');
        $this->addDecorator('form');

        return $this;
    }

    public function imageEdit($userId){
        $this->setName('image_user_form');
        $this->setAction('/admin/users/image/user/' . $userId)
              ->setEnctype(Zend_Form::ENCTYPE_MULTIPART)
              ->setMethod('post');
        $this->setAttrib('id', 'image_user_form');
        $this->setIsArray(true);
        $this->setElementsBelongTo('user');

        $image = new Zend_Form_Element_File('imagen');
        $image->setLabel("Agregar Imagen: ")
                ->setAttrib('class', 'text-input')
                ->setMaxFileSize(8000000)
                ->setDescription('La imagen no es obligatoria')
                ->setRequired(true)
                ->addValidator('Count', false, 1)                // ensure only 1 file
                ->addValidator('Size', false, 10240000)            // limit to 10 meg
                ->addValidator('Extension', false, 'jpg,jpeg,png,gif'); // only JPEG, PNG, and GIFs

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Actualizar imagen')
                ->setAttrib('class', 'button')
                ->setAttrib('escape', false);



        $this->addElements(array($image, $submit));
        
        $this->setElementDecorators(array(
                'viewHelper',
                'label',
                'errors',
                array('htmlTag',array('tag' =>'p'))

        ));

        $this->imagen->setDecorators(array(
                    'file',
                    'description',
                    'label',
                    'errors',
                    array('htmlTag',array('tag' =>'p'))
                ));
        
        $this->submit->removeDecorator('Label');
        return $this;

    }

    public function searchUser(){
        $this->setName('search_user_form');
        $this->setAction('/admin/users/search')
              ->setMethod('post');
        $this->setAttrib('id', 'search_user_form');
        $this->setIsArray(true);
        $this->setElementsBelongTo('user');

        $query = new Zend_Form_Element_Text('q');
        $query->setLabel('Texto:')
                ->setRequired(true)
                ->setAttrib('class', 'text-input');
                
        $fields = array(1  =>'Usuario',
                        2 =>'Correo',
                        3 => 'Nombre',
                        4 => 'Rol');
        $field = new Zend_Form_Element_Select('field');
        $field->setLabel('Buscar en campo:')
            ->setMultiOptions($fields);

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Buscar Usuario')
                ->setAttrib('class', 'button')
                ->setAttrib('escape', false);

        $this->addElements(array($query, $field,$submit));

        $this->setElementDecorators(array(
                'viewHelper',
                'label',
                'errors',
                array('htmlTag',array('tag' =>'p'))

        ));

        $this->addDecorator('formElements');
        $this->submit->removeDecorator('Label');
        $this->addDecorator('form');

        return $this;
    }
}
